<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="设备名称">
              <a-input placeholder="请输入计划名称" v-model="queryParam.shebeiname"></a-input>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="设备编号">
              <a-input placeholder="请输入设备编号" v-model="queryParam.shebeibianhao"></a-input>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="保养状态">
              <j-dict-select-tag type="list" v-model="queryParam.zhuangtai" dictCode="baoyangzhuangtai" placeholder="请选择所属分组" />
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <a-button type="primary" icon="download" @click="handleExportXls('gd_baoyang_renwu')">导出</a-button>
    </div>

    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a style="font-weight: 600">{{
          selectedRowKeys.length }}</a>项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div>

      <a-table ref="table" size="middle" :scroll="{ x: true }" bordered rowKey="id" :columns="columns"
        :dataSource="dataSource" :pagination="ipagination" :loading="loading" class="j-table-force-nowrap1"
        @change="handleTableChange">

        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text,record">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
          <img v-else :src="getImgView(text)" :preview="record.id" height="25px" alt=""
            style="max-width:80px;font-size: 12px;font-style: italic;" />
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
          <a-button v-else :ghost="true" type="primary" icon="download" size="small" @click="downloadFile(text)">
            下载
          </a-button>
        </template>

        <span slot="action" slot-scope="text, record">
          <a @click="handleClaim(record)" v-if="record.zhuangtai===0 ">领取任务</a>
        </span>

      </a-table>
    </div>

    <gd-baoyang-renwu-modal ref="modalForm" @ok="modalFormOk"></gd-baoyang-renwu-modal>
  </a-card>
</template>

<script>

import '@/assets/less/TableExpand.less'
import { mixinDevice } from '@/utils/mixin'
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import GdBaoyangRenwuModal from './modules/GdBaoyangRenwuModal'
import { filterMultiDictText } from '@/components/dict/JDictSelectUtil'
import editor from '@toast-ui/editor'
import { httpAction } from '@/api/manage'

export default {
  name: 'GdBaoyangRenwuList',
  mixins: [JeecgListMixin, mixinDevice],
  components: {
    GdBaoyangRenwuModal
  },
  data() {
    return {
      description: 'gd_baoyang_renwu管理页面',
      // 表头
      columns: [
        {
          title: '设备名称',
          align: "center",
          dataIndex: 'shebeiname'
        },
        {
          title: '计划名称',
          align: "center",
          dataIndex: 'name'
        },
        {
          title: '保养层级',
          align: "center",
          dataIndex: 'cengji_dictText'
        },
        {
          title: '保养方式',
          align: "center",
          dataIndex: 'fangshi_dictText'
        },
        {
          title: '保养周期（天）',
          align: "center",
          dataIndex: 'jiangeshichang'
        },
        {
          title: '开始时间',
          align: "center",
          dataIndex: 'createTime',
          customRender: function (text) {
            return !text ? "" : (text.length > 10 ? text.substr(0, 10) : text)
          }
        },
        {
          title: '预计时间',
          align: "center",
          dataIndex: 'guoqitianshu',
          customRender: function (text) {
            return !text ? "" : (text.length > 10 ? text.substr(0, 10) : text)
          }
        },
        {
          title: '保养时间',
          align: "center",
          dataIndex: 'zhixingshijian',
          customRender: function (text) {
            return !text ? "" : (text.length > 10 ? text.substr(0, 10) : text)
          }
        },
        {
          title: '保养状态',
          align: "center",
          dataIndex: 'zhuangtai_dictText'
        },
        {
          title: '执行人',
          align: "center",
          dataIndex: 'fuzeren_dictText'
        },
        {
          title: '操作',
          dataIndex: 'action',
          align: "center",
          fixed: "right",
          width: 147,
          scopedSlots: { customRender: 'action' }
        }
      ],
      url: {
        list: "/gongdan/gdBaoyangRenwu/list",
        delete: "/gongdan/gdBaoyangRenwu/delete",
        edit: "/gongdan/gdBaoyangGongdan/edit",
        exportXlsUrl: "/gongdan/gdBaoyangRenwu/exportXls",
        importExcelUrl: "gongdan/gdBaoyangRenwu/importExcel",

      },
      dictOptions: {},
      superFieldList: [],
    }
  },
  created() {
    this.getSuperFieldList();
  },
  computed: {
    importExcelUrl: function () {
      return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
    },
  },
  methods: {
    handleClaim(record) {
      httpAction(this.url.edit, record, "PUT").then((res) => {
        if (res.success) {
          that.$message.success(res.message);
          that.$emit('ok');
        } else {
          that.$message.warning(res.message);
        }
      })
      this.loadData()
    },
    initDictConfig() {
    },
    getSuperFieldList() {
      let fieldList = [];
      fieldList.push({ type: 'string', value: 'name', text: '计划名称', dictCode: '' })
      fieldList.push({ type: 'string', value: 'bianhao', text: '计划编号', dictCode: '' })
      fieldList.push({ type: 'int', value: 'cengji', text: '保养层级', dictCode: 'baoyangcengji' })
      fieldList.push({ type: 'int', value: 'fangshi', text: '保养方式', dictCode: 'baoyangfangshi' })
      fieldList.push({ type: 'int', value: 'guoqitianshu', text: '过期天数', dictCode: '' })
      fieldList.push({ type: 'int', value: 'jiangeshichang', text: '间隔时长', dictCode: '' })
      fieldList.push({ type: 'Text', value: 'beizhu', text: '备注', dictCode: '' })
      fieldList.push({ type: 'int', value: 'zhuangtai', text: '保养状态', dictCode: 'baoyangzhuangtai' })
      fieldList.push({ type: 'string', value: 'shebeiname', text: '设备名称', dictCode: '' })
      fieldList.push({ type: 'string', value: 'shebeibianhao', text: '设备编号', dictCode: '' })
      fieldList.push({ type: 'string', value: 'fuzeren', text: '执行人', dictCode: '' })
      fieldList.push({ type: 'string', value: 'fuzerenXingming', text: '负责人姓名', dictCode: '' })
      fieldList.push({ type: 'date', value: 'zhixingshijian', text: '执行时间' })
      this.superFieldList = fieldList
    }
  }
}
</script>
<style scoped>
@import '~@assets/less/common.less';
</style>